# coding=utf-8
# 防止中文乱码
import time
from flask_apscheduler import APScheduler

# @singleton
from api.appspath.appspath import task_UpdataInfos


class TaskHelper(APScheduler):
  def __new__(cls, *args, **kwargs):

    if not hasattr(cls, '_instance'):
      cls._instance = super().__new__(cls)

    return cls._instance

  def __init__(self, scheduler=None, app=None):
    super().__init__(scheduler, app)
    self.jobs = [
      {
        'id': 'job1',
        'func': task_UpdataInfos,
        'trigger': 'interval',
        'seconds': 3600
      }
      # {
      #   'id': 'job2',
      #   'func': self.method_test2,
      #   'trigger': 'interval',
      #   'seconds': 5
      # }
    ]
    for job in self.jobs:
      self.add_job(job['id'], job['func'], trigger=job['trigger'], seconds=job['seconds'])

  def startJobs(self):
    self.start()

  def method_test(self):
    print(str(time.time()))

  def method_test2(self):
    print('method_test2:' + str(time.time()))


myTaskHelper = TaskHelper()